﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using HslCommunication.Core;
using HslCommunication.Core.IMessage;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Omron
{
	/// <summary>
	/// 欧姆龙PLC通讯类，采用Fins-Tcp通信协议实现，支持的地址信息参见api文档信息。<br />
	/// Omron PLC communication class is implemented using Fins-Tcp communication protocol. For the supported address information, please refer to the api document information.
	/// </summary>
	/// <remarks>
	/// <note type="important">实例化之后，使用之前，需要初始化三个参数信息，具体见三个参数的说明：<see cref="P:HslCommunication.Profinet.Omron.OmronFinsNet.SA1" />，<see cref="P:HslCommunication.Profinet.Omron.OmronFinsNet.DA1" />，<see cref="P:HslCommunication.Profinet.Omron.OmronFinsNet.DA2" /></note>
	/// <note type="important">第二个需要注意的是，当网络异常掉线时，无法立即连接上PLC，PLC对于当前的节点进行拒绝，如果想要支持在断线后的快速连接，就需要将
	/// <see cref="P:HslCommunication.Profinet.Omron.OmronFinsNet.IsChangeSA1AfterReadFailed" />设置为<c>True</c>，详细的可以参考 <see cref="P:HslCommunication.Profinet.Omron.OmronFinsNet.IsChangeSA1AfterReadFailed" /></note>
	/// <br />
	/// <note type="warning">如果在测试的时候报错误码64，经网友 上海-Lex 指点，是因为PLC中产生了报警，如伺服报警，模块错误等产生的，但是数据还是能正常读到的，屏蔽64报警或清除plc错误可解决</note>
	/// <br />
	/// <note type="warning">如果碰到NX系列连接失败，或是无法读取的，需要使用网口2，配置ip地址，网线连接网口2，配置FINSTCP，把UDP的端口改成9601的，这样就可以读写了。</note>
	/// </remarks>
	/// <example>
	/// 地址列表：
	/// 地址支持的列表如下：
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>示例</term>
	///     <term>地址进制</term>
	///     <term>字操作</term>
	///     <term>位操作</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>DM Area</term>
	///     <term>D</term>
	///     <term>D100,D200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>CIO Area</term>
	///     <term>C</term>
	///     <term>C100,C200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>Work Area</term>
	///     <term>W</term>
	///     <term>W100,W200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>Holding Bit Area</term>
	///     <term>H</term>
	///     <term>H100,H200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>Auxiliary Bit Area</term>
	///     <term>A</term>
	///     <term>A100,A200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>EM Area</term>
	///     <term>E</term>
	///     <term>E0.0,EF.200,E10.100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	/// </list>
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="Usage" title="简单的短连接使用" />
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="Usage2" title="简单的长连接使用" />
	/// </example>
	// Token: 0x0200005A RID: 90
	public class OmronFinsNet : NetworkDeviceBase
	{
		/// <summary>
		/// 实例化一个欧姆龙PLC Fins帧协议的通讯对象<br />
		/// Instantiate a communication object of Omron PLC Fins frame protocol
		/// </summary>
		// Token: 0x06000770 RID: 1904 RVA: 0x00027430 File Offset: 0x00025630
		public OmronFinsNet()
		{
			base.WordLength = 1;
			base.ByteTransform = new ReverseWordTransform();
			base.ByteTransform.DataFormat = DataFormat.CDAB;
			base.ByteTransform.IsStringReverseByteWord = true;
		}

		/// <summary>
		/// 指定ip地址和端口号来实例化一个欧姆龙PLC Fins帧协议的通讯对象<br />
		/// Specify the IP address and port number to instantiate a communication object of the Omron PLC Fins frame protocol
		/// </summary>
		/// <param name="ipAddress">PLCd的Ip地址</param>
		/// <param name="port">PLC的端口</param>
		// Token: 0x06000771 RID: 1905 RVA: 0x000274D0 File Offset: 0x000256D0
		public OmronFinsNet(string ipAddress, int port)
		{
			base.WordLength = 1;
			this.IpAddress = ipAddress;
			this.Port = port;
			base.ByteTransform = new ReverseWordTransform();
			base.ByteTransform.DataFormat = DataFormat.CDAB;
			base.ByteTransform.IsStringReverseByteWord = true;
		}

		/// <inheritdoc />
		// Token: 0x06000772 RID: 1906 RVA: 0x00027580 File Offset: 0x00025780
		protected override INetMessage GetNewNetMessage()
		{
			return new FinsMessage();
		}

		/// <inheritdoc />
		// Token: 0x17000151 RID: 337
		// (get) Token: 0x06000773 RID: 1907 RVA: 0x00027587 File Offset: 0x00025787
		// (set) Token: 0x06000774 RID: 1908 RVA: 0x0002758F File Offset: 0x0002578F
		[HslMqttApi(HttpMethod = "GET", Description = "Get or set the IP address of the remote server. If it is a local test, then it needs to be set to 127.0.0.1")]
		public override string IpAddress
		{
			get
			{
				return base.IpAddress;
			}
			set
			{
				base.IpAddress = value;
				this.DA1 = Convert.ToByte(base.IpAddress.Substring(base.IpAddress.LastIndexOf(".") + 1));
			}
		}

		/// <summary>
		/// 信息控制字段，默认0x80<br />
		/// Information control field, default 0x80
		/// </summary>
		// Token: 0x17000152 RID: 338
		// (get) Token: 0x06000775 RID: 1909 RVA: 0x000275C3 File Offset: 0x000257C3
		// (set) Token: 0x06000776 RID: 1910 RVA: 0x000275CB File Offset: 0x000257CB
		public byte ICF { get; set; } = 128;

		/// <summary>
		/// 系统使用的内部信息<br />
		/// Internal information used by the system
		/// </summary>
		// Token: 0x17000153 RID: 339
		// (get) Token: 0x06000777 RID: 1911 RVA: 0x000275D4 File Offset: 0x000257D4
		// (set) Token: 0x06000778 RID: 1912 RVA: 0x000275DC File Offset: 0x000257DC
		public byte RSV { get; private set; } = 0;

		/// <summary>
		/// 网络层信息，默认0x02，如果有八层消息，就设置为0x07<br />
		/// Network layer information, default is 0x02, if there are eight layers of messages, set to 0x07
		/// </summary>
		// Token: 0x17000154 RID: 340
		// (get) Token: 0x06000779 RID: 1913 RVA: 0x000275E5 File Offset: 0x000257E5
		// (set) Token: 0x0600077A RID: 1914 RVA: 0x000275ED File Offset: 0x000257ED
		public byte GCT { get; set; } = 2;

		/// <summary>
		/// PLC的网络号地址，默认0x00<br />
		/// PLC network number address, default 0x00
		/// </summary>
		// Token: 0x17000155 RID: 341
		// (get) Token: 0x0600077B RID: 1915 RVA: 0x000275F6 File Offset: 0x000257F6
		// (set) Token: 0x0600077C RID: 1916 RVA: 0x000275FE File Offset: 0x000257FE
		public byte DNA { get; set; } = 0;

		/// <summary>
		/// PLC的节点地址，这个值在配置了ip地址之后是默认赋值的，默认为Ip地址的最后一位<br />
		/// PLC node address. This value is assigned by default after the IP address is configured. The default is the last bit of the IP address.
		/// </summary>
		/// <remarks>
		/// <note type="important">假如你的PLC的Ip地址为192.168.0.10，那么这个值就是10</note>
		/// </remarks>
		// Token: 0x17000156 RID: 342
		// (get) Token: 0x0600077D RID: 1917 RVA: 0x00027607 File Offset: 0x00025807
		// (set) Token: 0x0600077E RID: 1918 RVA: 0x0002760F File Offset: 0x0002580F
		public byte DA1 { get; set; } = 19;

		/// <summary>
		/// PLC的单元号地址，通常都为0<br />
		/// PLC unit number address, usually 0
		/// </summary>
		/// <remarks>
		/// <note type="important">通常都为0</note>
		/// </remarks>
		// Token: 0x17000157 RID: 343
		// (get) Token: 0x0600077F RID: 1919 RVA: 0x00027618 File Offset: 0x00025818
		// (set) Token: 0x06000780 RID: 1920 RVA: 0x00027620 File Offset: 0x00025820
		public byte DA2 { get; set; } = 0;

		/// <summary>
		/// 上位机的网络号地址<br />
		/// Network number and address of the computer
		/// </summary>
		// Token: 0x17000158 RID: 344
		// (get) Token: 0x06000781 RID: 1921 RVA: 0x00027629 File Offset: 0x00025829
		// (set) Token: 0x06000782 RID: 1922 RVA: 0x00027631 File Offset: 0x00025831
		public byte SNA { get; set; } = 0;

		/// <summary>
		/// 上位机的节点地址，假如你的电脑的Ip地址为192.168.0.13，那么这个值就是13<br />
		/// The node address of the upper computer. If your computer's IP address is 192.168.0.13, then this value is 13
		/// </summary>
		/// <remarks>
		/// <note type="important">假如你的电脑的Ip地址为192.168.0.13，那么这个值就是13</note>
		/// </remarks>
		// Token: 0x17000159 RID: 345
		// (get) Token: 0x06000783 RID: 1923 RVA: 0x0002763C File Offset: 0x0002583C
		// (set) Token: 0x06000784 RID: 1924 RVA: 0x00027654 File Offset: 0x00025854
		public byte SA1
		{
			get
			{
				return this.computerSA1;
			}
			set
			{
				this.computerSA1 = value;
				this.handSingle[19] = value;
			}
		}

		/// <summary>
		/// 上位机的单元号地址<br />
		/// Unit number and address of the computer
		/// </summary>
		// Token: 0x1700015A RID: 346
		// (get) Token: 0x06000785 RID: 1925 RVA: 0x00027668 File Offset: 0x00025868
		// (set) Token: 0x06000786 RID: 1926 RVA: 0x00027670 File Offset: 0x00025870
		public byte SA2 { get; set; }

		/// <summary>
		/// 设备的标识号<br />
		/// Device identification number
		/// </summary>
		// Token: 0x1700015B RID: 347
		// (get) Token: 0x06000787 RID: 1927 RVA: 0x00027679 File Offset: 0x00025879
		// (set) Token: 0x06000788 RID: 1928 RVA: 0x00027681 File Offset: 0x00025881
		public byte SID { get; set; } = 0;

		/// <summary>
		/// 如果设置为<c>True</c>，当数据读取失败的时候，会自动变更当前的SA1值，会选择自动增加，但不会和DA1一致，本值需要在对象实例化之后立即设置。<br />
		/// If it is set to <c> True </c>, when data reading fails, the current SA1 value will be automatically changed, and the automatic increase will be selected, but it will not be consistent with DA1. This value needs to be set immediately after the object is instantiated .
		/// </summary>
		// Token: 0x1700015C RID: 348
		// (get) Token: 0x06000789 RID: 1929 RVA: 0x0002768A File Offset: 0x0002588A
		// (set) Token: 0x0600078A RID: 1930 RVA: 0x00027692 File Offset: 0x00025892
		public bool IsChangeSA1AfterReadFailed { get; set; }

		/// <summary>
		/// 将普通的指令打包成完整的指令
		/// </summary>
		/// <param name="cmd"></param>
		/// <returns></returns>
		// Token: 0x0600078B RID: 1931 RVA: 0x0002769C File Offset: 0x0002589C
		private byte[] PackCommand(byte[] cmd)
		{
			byte[] array = new byte[26 + cmd.Length];
			Array.Copy(this.handSingle, 0, array, 0, 4);
			byte[] bytes = BitConverter.GetBytes(array.Length - 8);
			Array.Reverse(bytes);
			bytes.CopyTo(array, 4);
			array[11] = 2;
			array[16] = this.ICF;
			array[17] = this.RSV;
			array[18] = this.GCT;
			array[19] = this.DNA;
			array[20] = this.DA1;
			array[21] = this.DA2;
			array[22] = this.SNA;
			array[23] = this.SA1;
			array[24] = this.SA2;
			array[25] = this.SID;
			cmd.CopyTo(array, 26);
			return array;
		}

		/// <summary>
		/// 根据类型地址长度确认需要读取的指令头<br />
		/// Confirm the instruction header to be read according to the type address length
		/// </summary>
		/// <param name="address">起始地址</param>
		/// <param name="length">长度</param>
		/// <param name="isBit">是否是位读取</param>
		/// <returns>带有成功标志的报文数据</returns>
		// Token: 0x0600078C RID: 1932 RVA: 0x0002775C File Offset: 0x0002595C
		public OperateResult<byte[]> BuildReadCommand(string address, ushort length, bool isBit)
		{
			OperateResult<byte[]> operateResult = OmronFinsNetHelper.BuildReadCommand(address, length, isBit);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				result = OperateResult.CreateSuccessResult<byte[]>(this.PackCommand(operateResult.Content));
			}
			return result;
		}

		/// <summary>
		/// 根据类型地址以及需要写入的数据来生成指令头<br />
		/// Generate instruction header based on type address and data to be writtens
		/// </summary>
		/// <param name="address">起始地址</param>
		/// <param name="value">真实的数据值信息</param>
		/// <param name="isBit">是否是位操作</param>
		/// <returns>带有成功标志的报文数据</returns>
		// Token: 0x0600078D RID: 1933 RVA: 0x0002779C File Offset: 0x0002599C
		public OperateResult<byte[]> BuildWriteCommand(string address, byte[] value, bool isBit)
		{
			OperateResult<byte[]> operateResult = OmronFinsNetHelper.BuildWriteWordCommand(address, value, isBit);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				result = OperateResult.CreateSuccessResult<byte[]>(this.PackCommand(operateResult.Content));
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x0600078E RID: 1934 RVA: 0x000277DC File Offset: 0x000259DC
		protected override OperateResult InitializationOnConnect(Socket socket)
		{
			OperateResult<byte[]> operateResult = this.ReadFromCoreServer(socket, this.handSingle, true, true);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				int num = BitConverter.ToInt32(new byte[]
				{
					operateResult.Content[15],
					operateResult.Content[14],
					operateResult.Content[13],
					operateResult.Content[12]
				}, 0);
				bool flag2 = num != 0;
				if (flag2)
				{
					result = new OperateResult(num, OmronFinsNetHelper.GetStatusDescription(num));
				}
				else
				{
					bool flag3 = operateResult.Content.Length >= 24;
					if (flag3)
					{
						this.DA1 = operateResult.Content[23];
					}
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x0600078F RID: 1935 RVA: 0x00027898 File Offset: 0x00025A98
		protected override void ExtraAfterReadFromCoreServer(OperateResult read)
		{
			base.ExtraAfterReadFromCoreServer(read);
			bool flag = !read.IsSuccess;
			if (flag)
			{
				bool isChangeSA1AfterReadFailed = this.IsChangeSA1AfterReadFailed;
				if (isChangeSA1AfterReadFailed)
				{
					byte sa = this.SA1;
					this.SA1 = sa + 1;
					bool flag2 = this.SA1 > 253;
					if (flag2)
					{
						this.SA1 = 1;
					}
					bool flag3 = this.SA1 == this.DA1;
					if (flag3)
					{
						sa = this.SA1;
						this.SA1 = sa + 1;
					}
					bool flag4 = this.SA1 > 253;
					if (flag4)
					{
						this.SA1 = 1;
					}
				}
			}
		}

		/// <inheritdoc />
		// Token: 0x06000790 RID: 1936 RVA: 0x00027938 File Offset: 0x00025B38
		[DebuggerStepThrough]
		protected override Task<OperateResult> InitializationOnConnectAsync(Socket socket)
		{
			OmronFinsNet.<InitializationOnConnectAsync>d__55 <InitializationOnConnectAsync>d__ = new OmronFinsNet.<InitializationOnConnectAsync>d__55();
			<InitializationOnConnectAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<InitializationOnConnectAsync>d__.<>4__this = this;
			<InitializationOnConnectAsync>d__.socket = socket;
			<InitializationOnConnectAsync>d__.<>1__state = -1;
			<InitializationOnConnectAsync>d__.<>t__builder.Start<OmronFinsNet.<InitializationOnConnectAsync>d__55>(ref <InitializationOnConnectAsync>d__);
			return <InitializationOnConnectAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 从欧姆龙PLC中读取想要的数据，返回读取结果，读取长度的单位为字，地址格式为"D100","C100","W100","H100","A100"<br />
		/// Read the desired data from the Omron PLC and return the read result. The unit of the read length is word. The address format is "D100", "C100", "W100", "H100", "A100"
		/// </summary>
		/// <param name="address">读取地址，格式为"D100","C100","W100","H100","A100"</param>
		/// <param name="length">读取的数据长度</param>
		/// <returns>带成功标志的结果数据对象</returns>
		/// <example>
		/// 假设起始地址为D100，D100存储了温度，100.6℃值为1006，D101存储了压力，1.23Mpa值为123，D102,D103存储了产量计数，读取如下：
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="ReadExample2" title="Read示例" />
		/// 以下是读取不同类型数据的示例
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="ReadExample1" title="Read示例" />
		/// </example>
		// Token: 0x06000791 RID: 1937 RVA: 0x00027984 File Offset: 0x00025B84
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<byte[]> operateResult = this.BuildReadCommand(address, length, false);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
				}
				else
				{
					OperateResult<byte[]> operateResult3 = OmronFinsNetHelper.ResponseValidAnalysis(operateResult2.Content, true);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<byte[]>(operateResult3);
					}
					else
					{
						result = OperateResult.CreateSuccessResult<byte[]>(operateResult3.Content);
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 向PLC写入数据，数据格式为原始的字节类型，地址格式为"D100","C100","W100","H100","A100"<br />
		/// Write data to PLC, the data format is the original byte type, and the address format is "D100", "C100", "W100", "H100", "A100"
		/// </summary>
		/// <param name="address">初始地址</param>
		/// <param name="value">原始的字节数据</param>
		/// <returns>结果</returns>
		/// <example>
		/// 假设起始地址为D100，D100存储了温度，100.6℃值为1006，D101存储了压力，1.23Mpa值为123，D102,D103存储了产量计数，读取如下：
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="WriteExample2" title="Write示例" />
		/// 以下是写入不同类型数据的示例
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="WriteExample1" title="Write示例" />
		/// </example>
		// Token: 0x06000792 RID: 1938 RVA: 0x00027A10 File Offset: 0x00025C10
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<byte[]> operateResult = this.BuildWriteCommand(address, value, false);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					OperateResult<byte[]> operateResult3 = OmronFinsNetHelper.ResponseValidAnalysis(operateResult2.Content, false);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = operateResult3;
					}
					else
					{
						result = OperateResult.CreateSuccessResult();
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Omron.OmronFinsNet.Read(System.String,System.UInt16)" />
		// Token: 0x06000793 RID: 1939 RVA: 0x00027A88 File Offset: 0x00025C88
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			OmronFinsNet.<ReadAsync>d__58 <ReadAsync>d__ = new OmronFinsNet.<ReadAsync>d__58();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<OmronFinsNet.<ReadAsync>d__58>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Omron.OmronFinsNet.Write(System.String,System.Byte[])" />
		// Token: 0x06000794 RID: 1940 RVA: 0x00027ADC File Offset: 0x00025CDC
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			OmronFinsNet.<WriteAsync>d__59 <WriteAsync>d__ = new OmronFinsNet.<WriteAsync>d__59();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<OmronFinsNet.<WriteAsync>d__59>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 从欧姆龙PLC中批量读取位软元件，地址格式为"D100.0","C100.0","W100.0","H100.0","A100.0"<br />
		/// Read bit devices in batches from Omron PLC with address format "D100.0", "C100.0", "W100.0", "H100.0", "A100.0"
		/// </summary>
		/// <param name="address">读取地址，格式为"D100","C100","W100","H100","A100"</param>
		/// <param name="length">读取的长度</param>
		/// <returns>带成功标志的结果数据对象</returns>
		/// <example>
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="ReadBool" title="ReadBool示例" />
		/// </example>
		// Token: 0x06000795 RID: 1941 RVA: 0x00027B30 File Offset: 0x00025D30
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<byte[]> operateResult = this.BuildReadCommand(address, length, true);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<bool[]>(operateResult2);
				}
				else
				{
					OperateResult<byte[]> operateResult3 = OmronFinsNetHelper.ResponseValidAnalysis(operateResult2.Content, true);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<bool[]>(operateResult3);
					}
					else
					{
						result = OperateResult.CreateSuccessResult<bool[]>(Enumerable.ToArray<bool>(Enumerable.Select<byte, bool>(operateResult3.Content, (byte m) => m > 0)));
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 向PLC中位软元件写入bool数组，返回是否写入成功，比如你写入D100,values[0]对应D100.0，地址格式为"D100.0","C100.0","W100.0","H100.0","A100.0"<br />
		/// Write the bool array to the PLC's median device and return whether the write was successful. For example, if you write D100, values [0] corresponds to D100.0 
		/// and the address format is "D100.0", "C100.0", "W100. 0 "," H100.0 "," A100.0 "
		/// </summary>
		/// <param name="address">要写入的数据地址</param>
		/// <param name="values">要写入的实际数据，可以指定任意的长度</param>
		/// <returns>返回写入结果</returns>
		/// <example>
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="WriteBool" title="WriteBool示例" />
		/// </example>
		// Token: 0x06000796 RID: 1942 RVA: 0x00027BE8 File Offset: 0x00025DE8
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<byte[]> operateResult = this.BuildWriteCommand(address, Enumerable.ToArray<byte>(Enumerable.Select<bool, byte>(values, (bool m) => m ? 1 : 0)), true);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					OperateResult<byte[]> operateResult3 = OmronFinsNetHelper.ResponseValidAnalysis(operateResult2.Content, false);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = operateResult3;
					}
					else
					{
						result = OperateResult.CreateSuccessResult();
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Omron.OmronFinsNet.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000797 RID: 1943 RVA: 0x00027C88 File Offset: 0x00025E88
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			OmronFinsNet.<ReadBoolAsync>d__62 <ReadBoolAsync>d__ = new OmronFinsNet.<ReadBoolAsync>d__62();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<OmronFinsNet.<ReadBoolAsync>d__62>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Omron.OmronFinsNet.Write(System.String,System.Boolean[])" />
		// Token: 0x06000798 RID: 1944 RVA: 0x00027CDC File Offset: 0x00025EDC
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool[] values)
		{
			OmronFinsNet.<WriteAsync>d__63 <WriteAsync>d__ = new OmronFinsNet.<WriteAsync>d__63();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<OmronFinsNet.<WriteAsync>d__63>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000799 RID: 1945 RVA: 0x00027D2E File Offset: 0x00025F2E
		public override string ToString()
		{
			return string.Format("OmronFinsNet[{0}:{1}]", this.IpAddress, this.Port);
		}

		// Token: 0x040001E3 RID: 483
		private byte computerSA1 = 11;

		// Token: 0x040001E7 RID: 487
		private readonly byte[] handSingle = new byte[]
		{
			70,
			73,
			78,
			83,
			0,
			0,
			0,
			12,
			0,
			0,
			0,
			0,
			0,
			0,
			0,
			0,
			0,
			0,
			0,
			1
		};
	}
}
